{template 'web/'.$cfg['floder'].'/base_menu'}
<div class="top_tab"> 
	<a href="{php echo $this->createWebUrl('lottery')}" class="layui-btn {if $operation != 'display'}layui-btn-primary{/if}">管理游戏</a> 
    <a href="{php echo $this->createWebUrl('lottery',array('op'=>'post'))}" class="layui-btn {if $operation != 'post'}layui-btn-primary{/if}">添加游戏</a> 
</div>

<style>
.awardrow input{ width:90px;display:inline-block}
.awardrow input.mtxt {width:60px;display:inline-block}
</style>
{if $operation == 'post'}
<div class="panelbox">
  <form action="" method="post" class="layui-form" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{php echo $id}" />
    <div class="panelbox-head"> {if !$id}添加游戏{else}编辑游戏{/if} </div>
    <div class="panelbox-body">
      {if $id}
      <div class="layui-form-item">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-block">
          <input type="text" class="layui-input" readonly value="{$_W['siteroot']}app/index.php?i={$_W['uniacid']}&c=entry&id={php echo $id}&do=game&m=j_hmoney"/>
          <div class="help-block"></div>
        </div>
      </div>
      {/if}
      <div class="layui-form-item">
        <label class="layui-form-label">活动标题</label>
        <div class="layui-input-block">
          <input type="text" class="layui-input" lay-verify="required" name="title" value="{$item['title']}"/>
          <div class="help-block">活动标题</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">开关</label>
        <div class="layui-input-block">
          <input type="checkbox" {if $item['status']==1}checked{/if} name="status"  value="1" lay-skin="switch" lay-text="启用|关闭"/>
          <div class="help-block">活动开关</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">所属店铺</label>
        <div class="layui-input-block form-inline">
          <select name="groupid" class="layui-input">
              <option value="0" {if $index==$item['groupid']} selected{/if}>全部店铺</option>
              {loop $groupary $index $row}
              <option value="{$index}" {if $index==$item['groupid']} selected{/if}>{$row}</option>
              {/loop}
          </select>
          <div class="help-block">此内容可用于多门店，或者是不同地区收款时，作为统计时使用</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">活动时间</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_daterange('acttime', array('start' => date('Y-m-d', $item['starttime']),'end'=> date('Y-m-d', $item['endtime'])))}
          <div class="help-block">活动时间</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">活动图片</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_image('thumb', $item['thumb']);}
          <div class="help-block">用于单图文回复的显示</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">转发小图</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_image('clientpic', $item['clientpic']);}
          <div class="help-block">转发到朋友圈或者朋友时的图标</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">活动简介</label>
        <div class="layui-input-block">
          <input type="text" class="layui-input" name="description" value="{$item['description']}"/>
          <div class="help-block">用于图文显示的简介和转发到朋友圈</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">转盘图片</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_image('zppic', $item['zppic']);}
          <div class="help-block">转盘文件，请使用PNG图片,481*482px</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">转盘指针</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_image('thumb_pointer', $item['thumb_pointer']);}
          <div class="help-block">转盘文件，请使用PNG图片,481*482px</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">背景图片</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_image('thumb_bg', $item['thumb_bg']);}
          <div class="help-block">640*1080px</div>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">背景颜色</label>
        <div class="layui-input-block">
          {php echo tpl_form_field_color("bgcolor", $item['bgcolor'])}
          <div class="help-block">背景颜色</div>
        </div>
      </div>
      
      <div class="layui-form-item">
        <label class="layui-form-label">抽奖项目</label>
        <div class="layui-input-block">
          <div style="margin-top:10px">
             <table class="table table-hover">
              <thead>
                <tr>
                  <th style="width:80px"><a href="#" title="打钩的就是中奖奖品，否则就不是" data-toggle="tooltip" data-placement="bottom" class="tips">是否奖品</a></th>
                  <th><a href="#" title="填写奖品名称" data-toggle="tooltip" data-placement="bottom" class="tips">奖品名称</a></th>
                  <th>总数量/剩余数量</th>
                  <th>奖品内容</th>
                  <th><a href="#" title="累加最好等于100" data-toggle="tooltip" data-placement="bottom" class="tips">中奖几率%</a></th>
                </tr>
              </thead>
              <tbody id="award">
                {php $i=0;}
                {loop $list $row}
                {php $step=45*(8-$i);}
                <tr class="awardrow">
                  <td><input type="checkbox" name="award-isprize[{$row['id']}]"  value="1" {if $row['isprize']} checked="checked"{/if} /></td>
                  <td><input type="text" name="award-level[{$row['id']}]" placeholder='如一等奖' class="form-control"  value="{$row['level']}" /></td>
                  <td><input type="text" name="award-total[{$row['id']}]" class="form-control" style="width:50px"  value="{$row['total']}" />/<input type="text" name="award-renum[{$row['id']}]" class="form-control"  value="{$row['renum']}" style="width:50px"/></td>
                  <td><input type="hidden" name="award-deg[{$row['id']}]"  value="{php echo $step}" /><input type='text' name="award-description[{$row['id']}]" value="{$row['description']}" class='form-control'/></td>
                  <td><input type="text" name="award-probalilty[{$row['id']}]" class="form-control mtxt"  value="{$row['probalilty']}" /></td>
                </tr>
                {php $i++}
                {/loop}
              </tbody>
            </table>
            <div class="help-block">
           中奖几率%:累加最好等于100;
            1、必须要有一个不是奖品的项目！不能全部为奖品，否则会出错！<br />2、转盘和奖品的顺序是顺时针计算。<br />3、奖品内容设置说明：a直接写奖品名称时，系统返回一串字符作为兑奖凭证；b卡券奖励，|卡券|卡券id1|卡券id2；c红包奖励，|红包|1-2,就是随机1元-2元</div>
        </div>
      </div>
      <div class="layui-form-item" style="margin-top:10px">
        <label class="layui-form-label">活动规则</label>
        <div class="layui-input-block">
          {php echo tpl_ueditor('rule', $item['rule']);}
          <div class="help-block">活动的相关说明和活动奖品介绍。</div>
        </div>
      </div>
      
      
    </div>
    <div class="panelbox-foot">
      <input type="hidden" name="token" value="{$_W['token']}" />
      <input class="layui-btn" type="submit" lay-submit="" name="submit" lay-filter="btnsmbmit" value="提交">
    </div>
  </form>
</div>
<style>
.awardrow input{ width:90px;}
.awardrow input.mtxt {width:60px;}
</style>
<script language="javascript">
layui.use(['layer', 'element','form'], function(){
	var layer = layui.layer
	,element = layui.element
	,form = layui.form;
	form.render();
	form.on('submit(btnsmbmit)', function(data){
		var index2=layer.load(1, {shade: [0.5,'#fff']});
		$.post("{php echo $this->createWebUrl('lottery',array('op'=>'postdata'))}",data.field,function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			var result=eval("("+returnstr+")");
			if(result.success){
                var id="{php echo $_GPC['id']}";
				layer.msg("修改成功",{icon:1,time:1500},function(){
					if(id){
                        location.href="{php echo $this->createWebUrl('lottery')}";
                    }else{
                        location.reload();
                    }
				});
			}else{
				layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
				return;
			}
		})
		
		return false;
	});
	
});
</script>
{elseif $operation == 'display'}
<div class="panelbox">
<form action="" method="post" class="layui-form" id="listform" enctype="multipart/form-data">
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
            <th style="width:30px;">#</th>
            <th>游戏名称</th>
            <th>活动范围</th>
            <th>时间设置</th>
            <th>状态</th>
            <th>奖品</th>
            <th style="text-align:right">操作</th>
          </tr>
        </thead>
        <tbody>
        {loop $list $row}
        <tr>
          <td></td>
          <td>{$row['title']}</td>
          <td>{if $row['groupid']}<span class="label label-info">{php echo $groupary[$row['groupid']]}</span>{else}<span class="label label-danger">全部</span>{/if}</td>
          <td><span class="label label-default">{php echo date("y-m-d",$row['starttime'])}</span><br /><span class="label label-default">{php echo date("y-m-d",$row['endtime'])}</span></td>
          <td>{if $row['status']}<span class="label label-success">开启</span>{else}<span class="label label-default">关闭</span>{/if}</td>
          <td>
          {loop $prizelist[$row['id']] $prize}
          <div><span class="label label-info">{$prize['level']}</span>：<span class="label label-info">{$prize['renum']}</span> | <span class="label label-info">{$prize['total']}</span></div>
          {/loop}
          </td>
          <td style="text-align:right">
          <a href="{php echo $this->createWebUrl('lottery',array('op' => 'joiner','gid' => $row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe613;</i></a>
          <a href="{php echo $this->createWebUrl('lottery',array('op' => 'post', 'id' => $row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a>
          <a href="javascript:deleteContent('{php echo $this->createWebUrl('lottery',array('op'=>'delete','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a>
          </td>
        </tr>
        {/loop}
          </tbody>
      </table>
    </div>
  </div>
  </form>
</div>
<script language="javascript">
layui.use(['layer', 'laypage', 'element','form'], function(){
  var layer = layui.layer
  ,laypage = layui.laypage
  ,element = layui.element
  ,form = layui.form;
});
</script>
{/if}
